package com.hurt.competition.admin.controller;

import com.hurt.competition.admin.dto.CompetitionReq;
import com.hurt.competition.admin.model.Competition;
import com.hurt.competition.admin.service.CompetitionService;
import com.hurt.competition.common.util.CoreResultBuilder;
import com.hurt.competition.common.vo.CoreResult;
import com.hurt.competition.common.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("competition")
public class CompetitionController {

    @Autowired
    private CompetitionService competitionService;

    @PostMapping("page")
    private CoreResult page(@RequestBody CompetitionReq req){
        PageResult<Competition> page = competitionService.queryList(req);
        return CoreResultBuilder.success(page);
    }

    // 发布比赛
    @PostMapping("deploy")
    private CoreResult deploy(@RequestBody Competition competition){
        competitionService.deploy(competition);
        return CoreResultBuilder.success("deploy successful!");
    }

    // 编辑比赛
    @PostMapping("update")
    private CoreResult update(@RequestBody Competition competition){
        competitionService.updateById(competition);
        return CoreResultBuilder.success("update successful!");
    }

    // 删除比赛
    @PostMapping("delete")
    private CoreResult delete(@RequestBody Competition competition){
        competitionService.removeById(competition);
        return CoreResultBuilder.success("delete successful!");
    }
}
